 package com.slashmobility.finapps;

import com.droidux.samples.trial.R;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.BounceInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivitySplash extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		
		ImageView imageDroid = (ImageView) findViewById(R.id.imageChart);
		ImageView imageCaixa = (ImageView) findViewById(R.id.imageCaixa);
		
		TranslateAnimation tAnim = new TranslateAnimation(0, 0, -1000, 0);
		tAnim.setInterpolator(new BounceInterpolator());
		tAnim.setDuration(1000);
	 
		imageDroid.startAnimation(tAnim);
		imageCaixa.startAnimation(tAnim);
	    
		final TextView label = (TextView) findViewById(R.id.label);	

		final TranslateAnimation tAnimLabel = new TranslateAnimation(500, 0, 0, 0);
		tAnimLabel.setDuration(500);
		
		tAnim.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				label.setVisibility(View.VISIBLE);
				label.startAnimation(tAnimLabel);
			}
		});
		
	    new SplashTimer().execute((Object) null);
	}
	
	private class SplashTimer extends AsyncTask<Object, Object, Object> {
		private final int SLEEP_TIME = 1000*4;
		
		@Override
		protected Object doInBackground(Object... params) {
			try {
				Thread.sleep(SLEEP_TIME);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
		
		@Override
		protected void onPostExecute(Object result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			Intent i = new Intent(ActivitySplash.this, ActivityMain.class);
			startActivity(i);
			finish();
		}
	}
}
